package Package.Example.Consumers;

import java.util.function.Consumer;

public class Consumers {
    public static final void Consumers(){
//        案例需求
//String[] strArray = {"林青霞,30", "张曼玉,35", "王祖贤,33"};
//字符串数组中有多条信息，请按照格式：“姓名：XX,年龄：XX"的格式将信息打印出来
//要求：
//把打印姓名的动作作为第一个Consumer接口的Lambda实例
//把打印年龄的动作作为第二个Consumer接口的Lambda实例
//将两个Consumer接口按照顺序组合到一起使用
        String[] strArray = {"林青霞,30", "张曼玉,35", "王祖贤,33"};
        printInfo(strArray,(S)->{
            System.out.println("NAME:"+S.split(",")[0]);
        },S->{
            System.out.println("sex:"+S.split(",")[1]);
        });

    }
    private static final void printInfo(String[] strArray, Consumer<String> con1,
                                        Consumer<String> con2){
        for (String s:strArray
             ) {
            con1.andThen(con2).accept(s);
        }
    }
}
